package com.codemeta.bokit.sample.all.config;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author hice
 * @date 2021/11/19
 */
@Slf4j
@Configuration
public class SaTokenSecurityWebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(new SaRouteInterceptor((req, res, handler) -> {
            // 根据路由划分模块，不同模块不同鉴权
            SaRouter.match("/member/**", r -> StpUtil.checkLogin());
        })).addPathPatterns("/**");
        log.debug("all-sample添加sa-token路由拦截器");
    }
}